import { defineStore } from "pinia";
import { getProfile } from "@/api/auth";
import { getToken, setToken } from "@/utils/auth";

export const topUpDialogStore = defineStore("topUpDialog", {
  state: () => ({
    visible: false
  }),
  actions: {
    showDialog() {
      this.visible = true;
    },
    hideDialog() {
      this.visible = false;
    },
    updateBalance() {
      getProfile().then(res => {
        const userInfo = getToken();
        userInfo.balance = res.data.balance;
        setToken(userInfo);
      });
    }
  }
});
